package utils

import (
	"context"
	"github.com/sashabaranov/go-openai"
)

func OpenAIEmbedding(ctx context.Context, baseURL, key string, queryList []string) ([]openai.Embedding, error) {
	openAIConf := openai.DefaultConfig(key)
	openAIConf.BaseURL = baseURL
	client := openai.NewClientWithConfig(openAIConf)
	resp, err := client.CreateEmbeddings(
		ctx,
		openai.EmbeddingRequest{
			Model: openai.AdaEmbeddingV2,
			Input: queryList,
		},
	)

	if err != nil {
		return nil, err
	}
	return resp.Data, nil
}
